<template>
	<view>
		<view class="logs_img">
			<image src="../../static/img/logo.jpg" mode="widthFix"></image>
		</view>
		<view class="logs_name">一席赣宴</view>
		<!-- <view class="logs_line"></view> -->
		<view class="logs_text">登录后开发者将获得以下权限</view>
		<view class="logs_desc">
			<text></text>
			获得你的公开信息（昵称、头像等）
		</view>
		<button class="power_button" v-if="!show" @click="WeChatUserInfo">一键登录</button>
		<button class="power_button" v-else open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机号快捷登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				logs: [],
				show: false,
				type: '',
				uid: '',
				seller_id:'',
				status:''
			}
		},
		onLoad(e) {
			if(e.type){
				this.status=e.type;
			}
			this.seller_id=	uni.getStorageSync('seller_id')
		},
		methods: {
			WeChatUserInfo(e) {

				let _ = this;
				uni.getUserProfile({
					desc: '授权确认',
					success(res1) {
						let {
							nickName,
							gender,
							avatarUrl
						} = res1.userInfo;
						uni.login({
							provider: 'weixin',
							success(res) {
								_.$get(_.$api.userWx_login, {
									nickname: nickName,
									headimgurl: avatarUrl,
									code: res.code,
									seller_id:_.seller_id?_.seller_id:''
									// seller_id:21
								}, (result) => {

									let {
										data
									} = result;
									if (data.code == 1) {
										getApp().globalData.isReload = true;
										uni.setStorageSync('userInfo', data.data);
										uni.setStorageSync('userToken', data.data.token);
									
										if (data.data.mobile) {
											if(_.status){
												setTimeout(() => {
													uni.navigateBack({});
												}, 1000)
											}else{
												_.$Toast('登录成功，将跳转到首页');
												setTimeout(() => {
													uni.reLaunch({
														url: '/pages/tabar/index'
													});
												}, 1000)
											}
											
										} else {
											_.show = true;
										}


									} else {
										_.$Toast(data.msg)
									}
								}, true)
							}
						})
					}
				})

			},

			getPhoneNumber(e) {
				let _ = this;
				uni.login({
					provider: 'weixin',
					success(res) {
						let {
							encryptedData,
							iv
						} = e.detail;
						let params = {
							encrytendData: encryptedData,
							iv,
							token: uni.getStorageSync('userToken'),
							code: res.code,
							data: ''
						};
						_.$post(_.$api.userMobile, params, (result) => {
							let {
								data
							} = result;
							if (data.code == 1) {
								
								if(_.status){
									setTimeout(()=>{
										uni.navigateBack({});
									},1000)
								}else{
									_.$Toast('登录成功，将跳转到首页');
									setTimeout(() => {
										uni.reLaunch({
											url: '/pages/tabar/index'
										});
									}, 1000)
								}
								
								
							} else {
								_.$Toast(data.msg)
							}
						})
					}
				})
			}
		}
	}
</script>

<style scoped>
	.logs_img {
		width: 85%;
		/* height: 150rpx;
		background: #FFE048; */
		border-radius: 10rpx;
		margin: 30rpx auto 0;
		padding: 10rpx;
		overflow: hidden;
	}

	.logs_img image {
		width: 100%;
		height: 100%;
			border-radius: 10rpx;
	}

	.logs_name {
		text-align: center;
		font-size: 36rpx;
		color: #333333;
		margin-top: 30rpx;
	}

	.logs_line {
		width: 630rpx;
		height: 2rpx;
		background: #EEEEEE;
		margin: 80rpx auto;
	}

	.logs_text {
		padding: 80rpx 60rpx 30rpx;
		font-size: 30rpx;
		color: #333333;
	}

	.logs_desc {
		padding: 0 60rpx;
		font-size: 30rpx;
		color: #999999;
		display: flex;
		align-items: center;
	}

	.logs_desc text {
		display: inline-block;
		height: 6rpx;
		width: 6rpx;
		border-radius: 50%;
		background: #999;
		display: inline-block;
		margin-right: 10rpx;
	}

	.power_button {
		width: 630rpx !important;
		height: 98rpx;
		line-height: 98rpx !important;
		background: #FF7133;
		border-radius: 10rpx;
		padding: 0;
		font-size: 36rpx;
		color: white;
		margin-top: 80rpx;
		font-weight: normal;
	}
</style>
